package edu.uj.petri.model;

import edu.uj.petri.commands.Memento;


/**
 * object implementation of arc
 * @author Piotrek
 */
class ArcObjectImpl extends ArcImpl {
    private Node from;

    private Node to;

    private ObjectModel model;

    public ArcObjectImpl(ObjectModel model) {
        this.model = model;
    }

    public void reverse() {
        Node temp=from;
        from=to;
        to=temp;
    }

    public void setFrom(Node node) {
        this.from = node;
    }

    public void setTo(Node node) {
        this.to = node;
    }

    public Node getFrom() {
        return from;
    }

    public Node getTo() {
        return to;
    }

    /**
     * stores internal state in a memento
     */
    public Memento getMemento() {
        ArcMemento retval = new ArcMemento();
        retval.from = this.from;
        retval.to = this.to;
        return retval;
    }

    /**
     * restores internal state of object to state stored in the memento
     */
    public void applyMemento(Memento memento) {
        if (!(memento instanceof ArcMemento))
            throw new IllegalArgumentException("invalid memento");
        ArcMemento am = (ArcMemento)memento;
        this.to = am.to;
        this.from = am.from;
    }
    
    private static final long serialVersionUID = -2494737230428873481L;
    
    static class ArcMemento extends Memento {
        private Node from;
        private Node to;
    }
}
